﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace Site3AI.Models
{
    public partial class Site3AIEntities : DbContext
    {
        public long LastIDSeed = 0;
        public long LastIDFix = 0;
        public static DateTime ZeroTime = new DateTime(2012, 1, 1);
        object newidlocker = new object();
        public string NewID()
        {
            long ts = (long)(DateTime.Now - ZeroTime).TotalSeconds;
            if (ts > LastIDSeed)
            {
                lock (newidlocker)
                {
                    if (ts > LastIDSeed)
                    {
                        LastIDFix = 0;
                        LastIDSeed = ts;
                    }
                }
            }
            return (LastIDSeed * 1000 + (LastIDFix++)).ToString().TrimEnd('0');

        }
    }
}